// pages/Phonetheme/Phonetheme.js
var app = getApp();

var Bmob = require('../../utils/Bmob-2.2.0.min.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageList: [],
    height: 0,
    imgWidth: 0,
    loadingCount: 10,
    image:'',
    themeid:0,
swiperInfo:'',
    hidden: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   var id=options.id;
   
   this.setData({
      id: id

   });
    this.getswiperInfo();

  },
  getswiperInfo:function(){
  var id=this.data.id;
  var that=this;
   
    var swiper = Bmob.Query("swiper");

  
    swiper.get(id).then(res => {
      that.setData({
        swiperInfo: res,
        themeid: res.themeid
      })
      that.dataInitial();

    })


  },
  dataInitial: function () {
    // app.pageDataInitial();
   
    this.get_image();


    this.getheight();
  },
  onImageLoad: function (e) {

    var that = this;
    that.setData({
      hidden: false
    });
    var themeid = Number(that.data.themeid);    
    var image = Bmob.Query("Phone_image");
    var loadingCount = that.data.loadingCount;
    var imageList = that.data.imageList;   
    image.equalTo("themeid", themeid);
    image.limit(10);
    image.skip(loadingCount);
    // featureinfo.include("goods_Info")
    image.find().then(res=>{
      imageList = imageList.concat(res);
      that.setData({
        imageList: imageList,
        loadingCount: loadingCount + 10,
        hidden: true
      })
    })
  },

  getheight: function () {
    var that = this;

    wx.getSystemInfo({
      success: function (res) {

        that.setData({
          height: res.windowHeight,
          img_height: res.screenWidth / 3 * 2436 / 1370,
          img_width: res.screenWidth / 3 - 5,
        })
      }
    })
  },
  get_image: function () {
    var that = this;
    var themeid=Number(that.data.themeid);
    
    var image = new Bmob.Query("Phone_image");
    console.log(themeid)
    image.equalTo("themeid", themeid);
    image.limit(10);
    // featureinfo.include("goods_Info")
    image.find().then(res=>{
      console.log(res);
      that.setData({
        imageList: res
      })
    })

  },

  previewImage: function (e) {

    var index = e.currentTarget.dataset.index;
    var image = this.data.imageList[index].image;
    var imagelist = [];

    imagelist.push(image);
    wx.previewImage({
      current: image, // 当前显示图片的http链接
      urls: imagelist
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})